package study;

import java.util.ArrayList;

public class Person2 {
    protected String name;
    protected int age;

    public Person2(String name,int age){
        this.name = name;
        this.age = age;
    }

    public void walk(){

    }

    public void eat(){

    }
}

class CivilServant extends Person2{
    private int salray;
    private int count;

    public CivilServant(String name, int age,int salary, int count){
        super(name,age);
        this.salray = salray;
        this.count = count;
    }

    @Override
    public void walk(){
        System.out.println("慢慢地走");
    }

    @Override
    public void eat(){
        System.out.println("大吃大喝");
    }

    public void cShow(){
        System.out.println("CivilServant{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", salary=" + salray +
                ", count=" + count +
                '}');
    }
}

class Worker extends Person2{
    private int salary;
    private String tec;

    public Worker(String name, int age, int salary, String tec){
        super(name,age);
        this.salary = salary;
        this.tec = tec;
    }

    @Override
    public void walk(){
        System.out.println("快跑");
    }

    @Override
    public void eat(){
        System.out.println("急匆匆吃");
    }

    public void wShow(){
        System.out.println( "Worker{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", salary=" + salary +
                ", tec='" + tec + '\'' +
                '}');
    }
}
class Processor extends Thread{
    public void run(){
        System.out.println("helloworld");
    }
}
class Test3{
    public static void main(String[] args){
        //Person[] peoples = new Person[6];
        ArrayList<Person2>peoples = new ArrayList<>();

        Person2 c1 = new CivilServant("小王",30,5000,30);
        Person2 c2 = new CivilServant("小李",32,6000,31);
        Person2 c3 = new CivilServant("张三",33,7000,32);
        Thread thread=new Thread(null,null,"hello",5);
        String m=Thread.currentThread().getName();
        int n = m.compareTo("dddd");
        thread.start();
        Thread t1=new Processor();
        t1.setName("t1");
        t1.setPriority(5);//设置优先级(由低到高1~10)
        Thread t2 = new Processor();
        t2.setName("t1");
        t2.setPriority(10);
        t1.start();//告诉JVM再分配一个新的栈给t线程，run不需程序员手动调用
        t2.start();//系统线程启动后自动调用run方法
        A a1 = new A();
        A a2 = new A();
        Thread t3 = new Thread(a1);
        Thread t4 = new Thread(a2);
        t3.start();
        t4.start();
        peoples.add(c1);
        peoples.add(c2);
        peoples.add(c3);

        Person2 w1 = new Worker("Jack",23,8922,"Android开发");
        Person2 w2 = new Worker("Rose",24,8900,"IOS开发");
        Person2 w3 = new Worker("Merry",25,8999,"Web开发");

        peoples.add(w1);
        peoples.add(w2);
        peoples.add(w3);

        for (Person2 p : peoples){
            //找到P到底是哪个类型的对象
            if (p instanceof CivilServant){
                //公务员
                CivilServant c = (CivilServant)p;
                c.cShow();
                c.walk();
                c.eat();
            }else {
                //员工
                Worker w = (Worker)p;
                w.wShow();
                w.walk();
                w.eat();
            }
        }
    }
    static class A extends Thread{
        public void run() {
            for (int i = 0; i < 5; i++) {
                for(long k=0;k<100000000;k++){
                    System.out.println("ddd");
                };
                System.out.println(":"+i);
            }
        }
    }
}